/*
 * Copyright (c) 2008 by 1eEurope (Switzerland) AG, Thalwil
 *
 * Customer:	1eEurope (Switzerland) AG
 * Project:		BKS
 * Created:		30.09.2008, WBL
 *
*/

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace By1eEurope.BKS.Controls
{
    /// <summary>
    /// Utililties to work in the SiteCollection
    /// </summary>
    public class SiteUtil
    {
        /// <summary>
        /// Reads the value from listitem field
        /// </summary>
        /// <param name="itemUrl">url to the listitem</param>
        /// <param name="fieldName">field of the listitem</param>
        /// <param name="value">Value of the field is assigned to this variable</param>
        /// <returns>true, if a value was assigned to the value-variable; false, if not</returns>
        public static bool TryGetValue(string itemUrl, string fieldName, out string value)
        {
            try
            {
                using (SPWeb web = SPContext.Current.Site.OpenWeb(itemUrl, false))
                {
                    SPListItem imageItem = web.GetListItem(itemUrl);
                    value = (string)imageItem[fieldName];
                    return true;
                }
            }
            catch
            {
                value = string.Empty;
                return false;
            }
        }
    }
}
